package com.woniuxy.ui;

import com.woniuxy.entity.Stu;
import com.woniuxy.service.StuService;
import com.woniuxy.service.impl.StuServiceImpl;

import java.util.Scanner;

/**
 * @author 作者
 * @create 2025-11-19 14:58
 */
public class Application {

    static Scanner scanner =new Scanner(System.in);
    static StuService stuService=new StuServiceImpl();

    public static void main(String[] args) throws Exception {
        boolean flag=true;
        while (flag) {
            System.out.println("欢迎进入系统,选择你要执行的操作");
            System.out.println("1.添加学生");
            System.out.println("2.查询所有学生");
            System.out.println("3.删除学生");
            System.out.println("4.修改学生");
            System.out.println("6.退出系统");
            int choice=scanner.nextInt();
            switch (choice){
                case 1:
                    addStudent();
                    break;
                case 2:
                    getAllStudents();
                    break;
                case 3:
                    removeStudent();
                    break;
                case 4:
                    modifyStudent();
                    break;
                case 5:
                    System.out.println("退出系统");
                    flag=false;
                    break;
                default:
                    System.out.println("输入错误，重新选择");
                    break;
            }
        }
    }

    private static void modifyStudent() throws Exception {
        //输入数据
        Stu stu=new Stu();
        System.out.println("输入学生学号");
        stu.setSid(scanner.nextInt());
        System.out.println("输入学生姓名");
        stu.setSname(scanner.next());
        System.out.println("输入学生密码");
        stu.setPwd(scanner.next());
        System.out.println("输入学生年龄");
        stu.setAge(scanner.nextInt());
        //表示层调用业务逻辑层
        stuService.modify(stu);
    }

    private static void removeStudent() throws Exception {
        //输入数据
        System.out.println("输入学生学号");
        int sid=scanner.nextInt();
        //表示层调用业务逻辑层
        stuService.removeBySid(sid);
    }

    private static void getAllStudents() throws Exception {
        stuService.getAll().forEach(System.out::println);
    }

    private static void addStudent() throws Exception {
        //输入数据
        Stu stu=new Stu();
        System.out.println("输入学生学号");
        stu.setSid(scanner.nextInt());
        System.out.println("输入学生姓名");
        stu.setSname(scanner.next());
        System.out.println("输入学生密码");
        stu.setPwd(scanner.next());
        System.out.println("输入学生年龄");
        stu.setAge(scanner.nextInt());
        //表示层调用业务逻辑层
        stuService.add(stu);
    }
}
